// team.js
class Team {
    constructor(name) {
        this.name = name;  // 队名
        this.matchesPlayed = 0;  // 已比赛的场数
        this.wins = 0;  // 赢的场数
        this.draws = 0;  // 平的场数
        this.losses = 0;  // 输的场数
        this.goalsScored = 0;  // 进球数
        this.goalsConceded = 0;  // 失球数
        this.points = 0;  // 积分
    }

    update(homeGoals, awayGoals, isHome) {
        this.matchesPlayed++;
        this.goalsScored += isHome ? homeGoals : awayGoals;
        this.goalsConceded += isHome ? awayGoals : homeGoals;

        if (homeGoals > awayGoals) {
            if (isHome) {
                this.wins++;
                this.points += 3;
            } else {
                this.losses++;
            }
        } else if (homeGoals === awayGoals) {
            this.draws++;
            this.points += 1;
        } else {
            if (isHome) {
                this.losses++;
            } else {
                this.wins++;
                this.points += 3;
            }
        }
    }

    toString() {
        return `${this.name}: ${this.matchesPlayed}场, 胜${this.wins}, 平${this.draws}, 负${this.losses}, 进${this.goalsScored}, 失${this.goalsConceded}, 积${this.points}分`;
    }
}

module.exports = Team;